import { IFeidaoAiMobile } from '@dfeidao/mobile/interfaces';
import { Button, List, ListItem, Root } from 'native-base';
import React from 'react';
import { ActivityIndicator, Image, ListView, RefreshControl, Text, TouchableOpacity, View } from 'react-native';
import { NavigationEvents } from 'react-navigation';
interface TaskData {
	_id: string;
	quote_job_name: string;
	contents_homework: string;
	personalized_setting: string;
	create_time_str: string;
}
export default function tpl(a: (action: string, ...args: unknown[]) => ((...args: unknown[]) => void), s: (...class_names: string[]) => {}, d: (d: string) => string | number | unknown, fd: IFeidaoAiMobile) {
	const task_data = d('dt') as TaskData[];
	const wushujv = d('wushujv') as string;
	const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
	if (task_data) {
		const new_len = Number(d('new_len'));
		const page_no = Number(d('page_no'));
		const len = task_data.length;
		const page_size = 20;
		return (
			<Root>
				<View style={{ height: '100%' }}>
					<NavigationEvents
						onWillFocus={a('a001')}
					/>
					<TouchableOpacity onPress={a('a002')}>
						<View style={s('btnTop')} >
							<Image source={require('../../imgs/bianji.png')} style={s('icon1')} />
							<Text style={{ fontSize: 16, marginLeft: 5 }}>发布作业</Text>
						</View>
					</TouchableOpacity>
					<List
						refreshControl={
							<RefreshControl
								onRefresh={a('a001')}
								colors={['#ff0000']}
								enabled={true}
								progressBackgroundColor="#ffffff"
								refreshing={false}
							/>}
						dataSource={ds.cloneWithRows(task_data)}
						onEndReached={a('a005', { page_no: page_no + 1 })}
						onEndReachedThreshold={0.1}
						renderRow={(data, secId, rowId) =>
							<ListItem>
								<View style={s('kuai')}>
									<TouchableOpacity onPress={a('a003', { job_no: data.job_no })}>

										<View style={s('ht1')}>
											<Text>{data.personalized_setting}</Text>
											<Text>{data.create_time_str}</Text>
										</View>
										<View style={s('ht2')}>
											<Text style={s('text1')} numberOfLines={1}>{data.contents_homework}</Text>
											<Text style={{ flex: 1 }}></Text>
										</View>
									</TouchableOpacity>

								</View>
								{(() => {
									if (len === Number(rowId) + 1 && len > page_size - 1) {
										if (new_len) {
											return (
												<View style={s('footer')}>
													<ActivityIndicator />
													<Text>正在加载更多数据</Text>
												</View>
											);
										} else {
											return (
												<View style={{ height: 30, backgroundColor: '#f4f4f4', position: 'absolute', bottom: 0, left: 0, right: 0 }}>
													<Text style={{ color: '#999999', fontSize: 14, marginTop: 5, marginBottom: 5, textAlign: 'center' }}>
														没有更多数据了
												</Text>
												</View>
											);
										}
									}
								})()}
							</ListItem>
						}
						disableLeftSwipe={true}
						disableRightSwipe={true}
						renderRightHiddenRow={(data, secId, rowId, rowMap) =>
							<View style={{ flexDirection: 'row' }} >

							</View>
						/*<View style={{ flexDirection: 'row' }}>
								<View style={s('xiangqing')} >
									<Button success onPress={a('a003', { job_no: data.job_no })}>
										<Text >详情</Text>
									</Button>
								</View>
								<View style={s('xiangqing')}>
									<Button danger onPress={a('a004', { job_no: data.job_no, secId, rowId, rowMap })} >
										<Text >删除</Text>
									</Button>
								</View>
							</View>*/}
					/>
				</View>
			</Root>
		);
	} else {
		if (wushujv === 'yes') {
			return (
				<View style={s('page')}>
					<Image source={require('../../imgs/wushuju.png')} style={{ width: 80, height: 80 }} />
					<Text style={{ fontSize: 20 }}>暂无数据</Text>
				</View>
			);
		} else {
			return (
				<View style={s('footer1')}>
					<ActivityIndicator color='blue' size="large" />
				</View>
			);
		}
	}
}
